package me.example.eureka;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author HZQ
 * @date 2018/3/1
 * @copyright sankuai.com
 */
@RestController
@Configuration
public class TestController {
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
    public String hello(@PathVariable String name) {
        RestTemplate template = getRestTemplate();
        String retVal = template.getForEntity("http://sayHello/hello/" + name, String.class).getBody();
        return "In Caller, " + retVal;
    }
}
